let express = require('express');
let app = express();
app.use(function (req, res, next) {
    let origin = req.headers.origin;
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Access-Control-Allow-Headers', 'name');
    res.setHeader('Access-Control-Allow-Methods', 'PUT');
    res.setHeader('Access-Control-Allow-Credentials', true)
    if (req.methods == 'OPTIONS') {
        res.send()
    }
    next()
})
app.get('/getData', function (req, res) {
    console.log(req.headers)
    res.end('我爱你')
})
app.put('/getData', function (req, res) {
    console.log(req.headers)
    res.end('我爱你')
})
app.listen(4000, function () {
    console.log('a2启动成功')
})